<div class="main-content">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <ol class="breadcrumb">
                    <li>
                        <i class="clip-file"></i>
                        <a href="#">
                            Ventas
                        </a>
                    </li>
                    <li class="active">
                        Facturación
                    </li>					
                </ol>
                <div class="page-header">
                    <h1>Pedidos  <small>Listado</small></h1>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <!-- start: DYNAMIC TABLE PANEL -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <i class="icon-external-link-sign"></i>
                        Pedidos
                        <div class="panel-tools">
                            <a class="btn btn-xs btn-link panel-collapse collapses" href="#">
                            </a>
                            <a class="btn btn-xs btn-link panel-config" href="#panel-config" data-toggle="modal">
                                <i class="icon-wrench"></i>
                            </a>
                            <a class="btn btn-xs btn-link panel-refresh" href="#">
                                <i class="icon-refresh"></i>
                            </a>
                            <a class="btn btn-xs btn-link panel-expand" href="#">
                                <i class="icon-resize-full"></i>
                            </a>
                            <!--<a class="btn btn-xs btn-link panel-close" href="#">
                                <i class="icon-remove"></i>
                            </a> -->
                        </div>
                    </div>
                    <div class="panel-body">
                        
                        <hr>

                        <table class="table table-striped table-bordered table-condensed table-hover table-full-width" id="sample_1">
                            <thead>
                                <tr>
                                   
                                    <th style="width: 10%">Codigo</th>
                                    <th style="width: 25%">Cliente</th>
                                    <th style="width: 10%">Venta Total</th>
                                    <th style="width: 13%">Fec. Venta</th>
                                    <th style="width: 10%">Estado</th>
                                    <th style="width: 22%">Vendedor</th>
                                    <th style="width: 5%">Anular</th>
                                    <th style="width: 5%">Ver</th>
                                   
                                    
                                </tr>
                            </thead>
                            <tbody>
                              <?php
                                if (!empty($pedidos)) :
                                    foreach ($pedidos as $fila):
                                    
                                    ?>  
                                    
                                       <tr>
                                           <td><?= $fila->pedi_codigo ?></td>
                                                                <td><?= $fila->pedi_clientenombre  ?></td>
                                                                <td><?= $fila->pedi_totalventa ?></td>
                                                                <td><?= $fila->pedi_fecventa  ?></td>
                                                                <td><?php  if($fila->pedi_estado==1){
                                                                    echo "<label style='color:  #090' >Abierto</label>"; 
                                                                }else if($fila->pedi_estado==2){
                                                                    echo "<label style='color: #E02222' >Anulado</label>";
                                                                }else{
                                                                    echo "<label>Cerrado</label>";
                                                                }
                                                                    
                                                                    ?></td>
                                                                <td><?= $fila->pedi_usuarionombre  ?></td>
                                                                <td><a title="anular" href="<?php echo base_url("ventas/proceso/anularpedido/$fila->pedi_pedido_id"); ?>" class='btn btn-danger tooltips panel-config'><i class='icon-remove'></i></a></td>
                                       <td><a title="ver" onclick="agregarCarrito(<?=$fila->pedi_pedido_id ?>)"  data-toggle="modal" href="#vtnFrmCli" class='btn btn-file tooltips panel-config'><i class='icon-eye-open'></i></a></td>
                                       </tr>

                                       	 <?php
                                    endforeach;
                                endif;
                                ?>       				
                            </tbody>
                        </table>

                    </div>
                </div>
                <!-- end: DYNAMIC TABLE PANEL -->
            </div>
        </div>
    </div>
</div>


<!-- Inicio Dialogo Modal Clientes -->
<div id="vtnFrmCli" class="modal fade" aria-hidden="true" role="dialog" tabindex="-1" style="display: none;" >
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" aria-hidden="true" data-dismiss="modal" type="button">
                    ×
                </button>
                <h4 class="modal-title" id="tituFrm">
                    Detalle de Pedido
                </h4>
            </div>
            <div class="modal-body">
                 <table class="table table-striped table-bordered table-condensed table-hover table-full-width" id="sample_2">
                            <thead>
                                <tr>
                                   
                                    <th style="width: 55%">Producto</th>
                                    <th style="width: 15%">Cantidad</th>
                                    <th style="width: 15%">P. Unitario</th>
                                    <th style="width: 15%">Sub Total</th>                             
                                   
                                </tr>
                            </thead>
                            <tbody id="tablaDet">
                                 				
                            </tbody>
                        </table>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" id="cerrarDetalle" data-dismiss="modal" type="button">
                    Cerrar
                </button>
               
            </div>
        </div>
    </div>
</div>
<!-- Final Dialogo Modal Clientes -->

<script type="text/javascript">
    
                                                          function agregarCarrito(id) {
                                                             
                                                                $.ajax({
                                                                    type: "POST",
                                                                    url: "detallepedidosgetall",
                                                                    data: {id: id}, //usarlo cuando se envía mediante POST
                                                                    contentType: "application/x-www-form-urlencoded; charset=utf-8",
                                                                    dataType: 'json',
                                                                    success: function(msg) {
                                                                                  var tabla = "";
                        $(msg).each(function() {
                if (this.registros !== null) {
                    for (var i = 0; i < this.registros.length; i++) {
                       
                        tabla += "<tr>" +
                                "<td>" + this.registros[i].detp_nombreproducto + "</td>" +
                                "<td>" + this.registros[i].detp_cant + "</td>" +
                                "<td>" + this.registros[i].detp_preciounidad + "</td>" +
                                "<td>" + this.registros[i].detp_preciototal + "</td>" +
                                "</tr>";
                    }
                }else{
                tabla = "<tr><td colspan='4'>No hay registros</td></tr>"
                }
            });
            
                                                                        $("#tablaDet").html(tabla);
                                                                     
                                                                       
                                                                    }
                                                                });
                                                            }
                                                            
 </script>